package java04;

import java.util.*;

class PersonSortable implements Comparable<PersonSortable> {
	private String name;
	private int age;

	public PersonSortable(String name, int age) {
		this.name = name;
		this.age = age;
	}

	public String toString() {
		return name + "-" + age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public int compareTo(PersonSortable o) {
		if (this.name.compareTo(o.getName()) != 0)
			return this.name.compareTo(o.getName());
		else {
			if (this.age > o.getAge())
				return 1;
			else if (this.age < o.getAge())
				return -1;
			else
				return 0;
		}
	}
}

public class Java41 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.nextLine());
		List<PersonSortable> per = new ArrayList<PersonSortable>();
		for (int i = 0; i < n; i++) {
			per.add(new PersonSortable(in.next(), in.nextInt()));
		}
		Collections.sort(per);
		for (PersonSortable person : per) {
			System.out.println(person);
		}
		System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
	}
}